<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" href="${base}/resources/css/main.css"/>
    <script type='text/javascript' src='${base}/resources/js/lib/jquery.1.11.3.min.js'></script>
    <script type='text/javascript' src='${base}/resources/js/lib/jquery.md5.js'></script>
    <script type='text/javascript' src='${base}/resources/js/common.js'></script>
</head>
<body>
<!-- 内容 -->
<div class='content'>
    <div class="login">
        <div class="banner"></div>
        <form id="loginForm" method="post">
            <div class="loginInp">
                <p>亿金融业务管理系统</p>
                <input name="password" type="hidden"/>
                <input name="userNameCheck" type="hidden" value="true"/>
                <div class="cf">
                    <input type='text' class="username" name="username" placeholder='用户名' data-bind="value:userName"/>
                    <span id="errorUserName" class="error"/>
                </div>
                <div class="cf">
                    <input type='password' class="password" name="companyPassword" placeholder='密码'
                           data-bind="value:password"/>
                    <span id="errorPassword" class="error"></span>
                </div>
                <div class="yzm cf">
                    <input type='text' name="imgCheckCode" placeholder='验证码' />
                    <img class="tuxiang" src="" id="changeimg" />
                    <a href="javascript:changeImg();">换一张</a>
                </div>
                <p class="remember checked checkBoxChange">记住用户名</p>
                <div class="btn cf">
	                <#-- <input class="checked" type="checkbox" id="isRememberUsername" value="true" />-->
	                <button type='button' id="login" class="loginbtn">注册</button>
	                <button type='button' id="login" class="loginbtn">登录</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
    var base = "${base}";
    $(function () {
        loadCookie();
        changeImg();
        $("#changeimg").bind("click", changeImg);
        $(".checkBoxChange").bind("click", checkBoxChange);
        $("#login").click(function () {
            var username = $("input[name='username']").val();
            var name = $("input[name='name']").val();
            var companyPassword = $("input[name='companyPassword']").val();
            if ($.isBlank(username)) {
                $("#errorUserName").text("用户名不能为空");
                return false;
            } else {
                $("#errorUserName").text("");
            }
            if ($.isBlank(companyPassword)) {
                $("#errorPassword").text("密码不能为空");
                return false;
            } else {
                $("#errorPassword").text("");
                $("input[name='password'").val($.md5(companyPassword));

            }
            $.ajax({
                url: base + '/passport/doLogin',
                type: 'post',
                data: $("#loginForm").serialize(),
                success: function (data) {
                    if (data.success) {
                        window.location.href = base + "/index";
                    } else {
                        changeImg();
                        alert(data.msg);
                    }
                }
            });
        })
    });

    function changeImg() {
        var t = new Date().valueOf();
        $("#changeimg").attr("src", '${base}/passport/checkcode?t=' + t)
    }

    function checkBoxChange() {
        $(this).toggleClass("checked");
        if ($(this).hasClass("checked")) {
            $("input[name='userNameCheck']").val("true")
        } else {
            $("input[name='userNameCheck']").val("false")
        }
    }
    function loadCookie() {
       var username ='${username}';
        if($.isBlank(username)){
            $(".checkBoxChange").removeClass("checked");
            $("input[name='userNameCheck']").val("false")
        }else {
            $("input[name='username']").val(username);
        }
    }
</script>
</html>